public class of12 {
    public static void main(String[] args) {
        char board[][]=new char[3][5];
    }
    public static boolean exist(char[][] board, String word) {
        char[] words = word.toCharArray();
        int k=0;
        for(int i=0;i<board.length;i++){
            for(int j=0;j<board[0].length;j++){
                if(_12dfs(board,words,i,j,k)) return true;
            }
        }
        return false;
    }
    static boolean _12dfs(char[][] board,char[] words, int i,int j,int k){
        if(i>=board.length||i<0||j>board[0].length||j<0||board[i][j]!=words[k])return false;
        if(k==words.length)return true;
        board[i][j]='\0';
        boolean res = _12dfs(board,words,i+1,j,k+1)||_12dfs(board,words,i,j+1,k+1)||_12dfs(board,words,i-1,j,k+1)||_12dfs(board,words,i,j-1,k+1);
        board[i][j]=words[k];
        return res;
    }
}
